//
//  SEGTarget_Login.m
//  SEGUhomeStandard
//
//  Created by 刘山 on 2018/3/19.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGTarget_Login.h"
#import "SEGLoginViewController.h"
#import "SEGChangePasswordViewController.h"
#import "SEGChangePhoneNumberViewController.h"
#import "SEGNewSelectCommunityViewController.h"
#import "SEGLogoutViewController.h"

#if __has_include(<BMKLocationKit/BMKLocationManager.h>)
#import <BMKLocationKit/BMKLocationManager.h>
#else
#import "BMKLocationManager.h"
#endif

#import <BaiduMapAPI_Base/BMKBaseComponent.h>
#import <BMKLocationkit/BMKLocationComponent.h>
#import <UMCommon/MobClick.h>

#if __has_include(<CommonMediator/SEGUhomeMediatorConfig.h>)
#import <CommonMediator/SEGUhomeMediatorConfig.h>
#else
#import "SEGUhomeMediatorConfig.h"
#endif

#if __has_include(<Commom/SEGCKeyChainStore.h>)
#import <Commom/SEGCKeyChainStore.h>
#else
#import "SEGCKeyChainStore.h"
#endif

#import <Commom/SEGSecurityManager.h>

#if __has_include(<Commom/SEGBasicNavigationController.h>)
#import <Commom/SEGBasicNavigationController.h>
#else
#import "SEGBasicNavigationController.h"
#endif

#import <WXApiObject.h>
#import <WXApi.h>
#import "SEGWebViewLoadManager.h"
@interface SEGTarget_Login ()<UIAlertViewDelegate>
@end

@implementation SEGTarget_Login

/**
 * 初始化登录界面
 * @author Sam
 * @param params  跳转参数
 */
-(UIViewController*)segAction_initLoginViewController:(NSDictionary*)params{
    if ([SEGUhomeMediatorConfig shared].initLoginVCBlock) {
        UIViewController *loginVC = [SEGUhomeMediatorConfig shared].initLoginVCBlock(params);
        return loginVC;
    }
    SEGLoginViewController *VC = [[SEGLoginViewController alloc]init];
    VC.messageDesc = params;
    return VC;
}

/**
 * 初始化百度地图
 * @author Sam
 * @param params  跳转参数
 */
-(void)segAction_initBMKLocationKit:(NSDictionary*)params{
     BMKMapManager *mapManager = [[BMKMapManager alloc] init];
    if (params && [params isKindOfClass:[NSDictionary class]] && [[params allKeys]containsObject:@"appKey"]) {
        [[BMKLocationAuth sharedInstance] checkPermisionWithKey:[params valueForKey:@"appKey"] authDelegate:nil];
        BOOL ret = [mapManager start:[params valueForKey:@"appKey"] generalDelegate:nil];
        if (ret) {}
    }
}

/**
 * 初始化选择小区
 * @author Sam
 * @param params  跳转参数
 */
-(UIViewController*)segAction_initSelectCommunityViewController:(NSDictionary*)params{

//    SEGSelectCommunityViewController *VC = [[SEGSelectCommunityViewController alloc]init];
//    VC.rowSelectType = [[params valueForKey:@"rowSelectType"] integerValue];

    //新选择小区界面
    SEGNewSelectCommunityViewController *VC = [[SEGNewSelectCommunityViewController alloc] init];
    
    VC.tel = [params valueForKey:@"tel"];
    VC.pwd = [params valueForKey:@"password"];
    VC.code = [params valueForKey:@"smsCode"];
    VC.randomToken = [params valueForKey:@"randomToken"];
    VC.isFromLogin = [[params valueForKey:@"isFromLogin"] boolValue];

    return VC;
}

/**
 * 初始化切换小区
 * @author Sam
 * @param params  跳转参数
 */
-(UIViewController*)segAction_initChangeCommunityViewController:(NSDictionary*)params{
//    SEGChangeCommunityViewController *VC = [[SEGChangeCommunityViewController alloc]init];
    
    //新选择小区界面
    SEGNewSelectCommunityViewController *VC = [[SEGNewSelectCommunityViewController alloc] init];
    return VC;
}

/**
 * 修改密码
 * @author Sam
 * @param params  跳转参数
 */
-(UIViewController*)segAction_initChangePasswordViewController:(NSDictionary*)params{
    
    SEGChangePasswordViewController *VC = [[SEGChangePasswordViewController alloc]init];
    return VC;
}

/**
 * 修改号码
 * @author Sam
 * @param params  跳转参数
 */
-(UIViewController*)segAction_initSEGChangePhoneNumberViewController:(NSDictionary*)params{
    
    SEGChangePhoneNumberViewController *VC = [[SEGChangePhoneNumberViewController alloc]init];
    return VC;
}

/// 注销账号
/// @param params 跳转参数
- (UIViewController *)segAction_initSEGLogoutViewController:(NSDictionary *)params {
    SEGLogoutViewController *vc = [[SEGLogoutViewController alloc] init];
    return vc;
}

/**
 * 跳转到登录界面
 * @author Sam
 */
-(void)segAction_pushToLoginViewController:(NSDictionary*)params{
    // 【等保改造】跳转到登录页面的时候 重置是否提示用户修改密码状态
    [SEGCommonConfig shared].isAlreadyAlterUesrChangePassword = NO;
    
    UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initLoginViewController:params];
    //[UIApplication sharedApplication].delegate.window.rootViewController = [[SEGUhomeMediator sharedInstance] seg_initNavigationController:@{@"vc":VC}];
    
    //[UIApplication sharedApplication].delegate.window.rootViewController = [[SEGUhomeMediator sharedInstance]seg_initLoginViewController:params];
    
//    [UIApplication sharedApplication].delegate.window.rootViewController = nil;
    UIViewController *newVC = [[SEGUhomeMediator sharedInstance] seg_initNavigationController:@{@"vc":VC}];
    
    [UIApplication sharedApplication].delegate.window.rootViewController = newVC;
    [UIView transitionWithView:[UIApplication sharedApplication].delegate.window duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [UIApplication sharedApplication].delegate.window.rootViewController = newVC;
    } completion:nil];
}

/**
 * 跳转到登录界面
 * @author Sam
 */
-(void)segAction_pushToViewControllerWithAction:(NSDictionary*)params{
     UIViewController *pushVC = [self currentViewController];
    // 跳转字段
    NSString *action = [[params allKeys]containsObject:@"action"]? ValueToString([params valueForKey:@"action"]) : @"";
    
    // 跳转的类型：0：内部跳转、1：网页跳转
    NSString *type = [[params allKeys]containsObject:@"type"]? ValueToString([params valueForKey:@"type"]) : @"";
    
    // 判断是否使用系统的浏览器打开URL:0：项目浏览器打开、1：系统浏览器打开
    NSString *isBrowser = [[params allKeys]containsObject:@"isBrowser"]? ValueToString([params valueForKey:@"isBrowser"]) : @"";
    
    NSString *instCode = [[params allKeys]containsObject:@"instCode"]? ValueToString([params valueForKey:@"instCode"]) : @"";
    
    // E.G : "com.segi.uhome.action."
    //NSString *bundleId = [NSString stringWithFormat:@"%@",[[NSBundle mainBundle] bundleIdentifier]];  //设备bundle id
    NSString *bundleId = @"cn.segi.uhome";  //设备bundle id
    
    // 服务名
    NSString *serviceName = [[params allKeys]containsObject:@"serviceName"]? ValueToString([params valueForKey:@"serviceName"]) : @"";
    
    NSString *userTypeString = [params valueForKey:@"userType"];
    NSArray* userType = [userTypeString componentsSeparatedByString:@"|"];
    
    if (userTypeString.length == 0) {
        //不存在 就 全部都可以访问
        userType = nil;
    }
    if (![self checkUserAuthority:userType]) { //判断非游客用户是否有权限使用此模块功能
        //非游客用户没有权限就直接返回
        return;
    }
    
    if ([type isEqualToString:@"1"]) { // 网页跳转
        if (action && [action isKindOfClass:[NSString class]] && [action length] > 0) {
            if ([isBrowser isEqualToString:@"1"]) { // 外部浏览器
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:action]];
                return;
            }
            
            NSDictionary *params = @{@"linkURL":action};
            UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:params];
            VC.title = serviceName;
            [pushVC.navigationController pushViewController:VC animated:YES];
        }
        return;
    }
    
    //活动
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.ACT",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initOtherCreatActivityRootListViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 我参与的活动
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.ACT_MANAGE_RECORD",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initMyParticipatedActivityController:@{@"displayTitle":ValueToString(serviceName)}];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //物业服务
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.APPOINTMENT",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initOrderInputViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //账单
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.BILL",bundleId]]) {
        
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
            [SEGAlertView showTmepMessageWithMessage:@"版本太低！"];
            return;
        }
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initBillListViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //欠费
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.BILL.ARREAR",bundleId]]) {
        
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
            [SEGAlertView showTmepMessageWithMessage:@"版本太低！"];
            return;
        }
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initBillDeatilViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //预缴
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.BILL.PREPAY",bundleId]]) {
        
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
            [SEGAlertView showTmepMessageWithMessage:@"版本太低！"];
            return;
        }
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initBillDeatilFutureViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //商圈
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.BUSINESS_CIRCLE",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initBusinessCircleRootViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //购物车
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.CART",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initShoppingCarRootViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //快递
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.EXPRESS",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initExpressCollectionListViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //团购
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.GROUP_BUY",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initGroupsShoppingRootViewController:@{@"instCode":instCode}];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    //新租赁
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.HOUSE_RENT_V2",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initNewMenuHouseViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    //租赁
//    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.HOUSE_RENT",bundleId]]) {
//        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initMenuHouseViewController:nil];
//        VC.title = serviceName;
//        [pushVC.navigationController pushViewController:VC animated:YES];
//        return;
//    }
    
    // 人脸识别
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.FACE_RECOGNITION",bundleId]]) {
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initFaceRecognitionViewController:nil];
        vc.title = serviceName ?: @"人脸识别";
        vc.hidesBottomBarWhenPushed = YES;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //帮帮
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.NEIGHBOR_LIST",bundleId]]) {
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initHelpRootViewController:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //物业通知
//    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.NEW",bundleId]]) {
//        NSDictionary *var = @{@"instCode":instCode,@"userInfo":@"",@"titleString":serviceName};
//        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initNewsListRootViewController:var];
//        vc.hidesBottomBarWhenPushed = YES;
//        [pushVC.navigationController pushViewController:vc animated:YES];
//        return;
//    }
    
    //黄页
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PAGE",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initObjectAdminViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //PGC详情
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PICTORIAL_LIST",bundleId]]) {
        
        return;
    }
    
    //拼车
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.RIDE",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initWayCarRootViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //访客通行
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.VISITOR_ACCESS",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initVisitorAccessViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //社区调查
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.SURVEY",bundleId]]) {
        
        return;
    }
    
    //视频监控
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.MONITOR",bundleId]]) {
        [SEGAlertView showTmepMessageWithMessage:@"视频监控功能暂时不提供！"];
        return;
    }
    
    //集市
    
    if ([action rangeOfString:[NSString stringWithFormat:@"%@.action.EXCHANGE",bundleId]].location != NSNotFound) {
        NSString *selectedIndex = @"0";//默认二手
        //出借
        if ([action rangeOfString:@"LENT"].location != NSNotFound) {
            selectedIndex = @"1"; //出借
        }
        else if ([action rangeOfString:@"BUSINESS"].location != NSNotFound) {
            selectedIndex = @"2";//小生意
        }
        else if ([action rangeOfString:@"GIFT"].location != NSNotFound) {
            selectedIndex = @"3";//赠送
        }
        NSDictionary *params = @{@"selectedIndex" : selectedIndex};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMarketListViewController:params];
        vc.title = serviceName;
        vc.hidesBottomBarWhenPushed = YES;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //月卡缴费
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.MOONCARD",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initMonthCardCheckViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //到家服务
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.HOME_SERVICE",bundleId]]) {
        
        NSDictionary *dict = @{@"linkURL":kHomeService};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:dict];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //到家服务详情
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.HOME_SERVICE_DETAIL",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:[params valueForKey:@"detailUrl"]];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    
    //招商一卡通
    if ([action rangeOfString:[NSString stringWithFormat:@"%@.action.CMHK_YIKATONG",bundleId]].location != NSNotFound) {
        NSDictionary *dict = @{@"linkURL":kWebCMHKYIKATONG};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:dict];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //招商在线缴费
    if ([action rangeOfString:[NSString stringWithFormat:@"%@.action.CMHK_PAYONLINE",bundleId]].location != NSNotFound) {
        NSString *custId = [SEGProfileManager sharedManager].profile.custId;
        NSDictionary *dict = @{@"linkURL":kWebCMHKPayOnline(action, custId)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:dict];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //招商停车场月卡入口
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.CMP_MONTH_CARD",bundleId]]) {
        
        return;
    }
    
    //招商停车场临卡入口
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.CMP_TEMP_CARD",bundleId]]) {
        
        return;
    }
    
    //话题
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.TALK_LIST",bundleId]]) {
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initTalkSquareViewController:nil];
        vc.title = serviceName;
        vc.hidesBottomBarWhenPushed = YES;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //团购详情
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.GROUPBUY_DETAIL",bundleId]]) {
        
        NSDictionary *dict = @{@"serviceId":instCode};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initGroupsShoppingDetailViewController:dict];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //画报详情
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PICTORIAL_DETAIL",bundleId]]) {
        
        return;
    }
    
    //自助洗车
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.FLASHBOX",bundleId]]) {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
            [SEGAlertView showTmepMessageWithMessage:@"版本太低！"];
            return;
        }
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWashCarViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //活动管理列表
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.ACT_MANAGE_LIST",bundleId]]) {
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initActivityManageRootViewController:nil];
        vc.hidesBottomBarWhenPushed = YES;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //网页跳转  --  数字社区
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.DIGITAL_COMMUNITY",bundleId]]) {
        
        SEGProfileModel *account = [SEGProfileManager sharedManager].profile;
        NSString *digitalUrl = [NSString stringWithFormat:@"%@%@#/digitalCommunity?communityId=%@&badge=%@&user_type=%@",
                                kClientRootURL,
                                kNewShareURLPre,
                                kAccountCommunityID,
                                [ValueToString(account.type) isEqualToString:@"5"] ? ([ValueToString(account.submitAuthFlag) isEqualToString:@"1"] ? @"0" : @"1") : @"0",
                                ValueToString(account.type)];
        
        NSDictionary *dict = @{@"linkURL":digitalUrl,
                               @"shouldResetNavgation":@(1),
                               @"isDigitalComunity":@(YES)
                               };
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:dict];
        VC.title = @"数字社区";
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //物业公众号 -- 工单记录（原我的服务）
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.APPOINTMENT.RECORD",bundleId]]) {
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMyServiceListViewController:nil];
        vc.title = serviceName;
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    // 子菜单展开
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.MENU",bundleId]]) {
        if ([params valueForKey:@"childList"]) {
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMenuChildListViewController:@{@"childList":[params valueForKey:@"childList"],@"serviceName":serviceName}];
            vc.title = serviceName;
            [pushVC.navigationController pushViewController:vc animated:YES];
        }
        return;
    }
    
    // 五星好评
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.FIVESTAR",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initUhomeListViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 优秀员工
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.GOODSTAFF",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initExcellentWorkersViewController:@{@"introId":ValueToString([params valueForKey:@"introId"])}];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 访客管理-人脸识别
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.FaceOpen",bundleId]]) {
        NSDictionary *params = @{@"linkURL":kWebVisitorManagement(kAccountCommunityID,kAccountMobile,kAccountNickName)};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
        vc.title = @"访客管理";
        [pushVC.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    // 房屋认证
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.HOUSE_CERTIFICATION",bundleId]] ||
        [action isEqualToString:[NSString stringWithFormat:@"%@.action.DIGITAL_HOUSE_MANAGE",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initDigitalComRootViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 切换社区
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.COMMUNITY_LIST",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initChangeCommunityViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 个人资料
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PROFILE",bundleId]]) {
        //NSDictionary *var = @{@"requestUserId":serviceName};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initMyProfileViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 个人主页
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PERSONAL_HOMEPAGE",bundleId]]) {
        NSDictionary *params = @{@"requestUserId":kAccountUserID};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initSEGPersonalHomePageNewViewController:params];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //我的-订单
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.COMMUNITYBUSS_ORDERS_ALL_ORDERS",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initSEGOrderViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //订单-到家服务
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.ORDERLIST_HOMESERVICE",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initHS_ViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //订单-团购
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.ORDERLIST_GROUPBUY",bundleId]]) {
        
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initMyOrderViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //收藏
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.COLLECT",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initMyCollectionViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //邀请邻居
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.SHARE_APP_MAIN",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initInviteViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //产品反馈
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.PRODUCT_FEEDBACK",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initUserFeedbackViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        
        return;
    }
    
    //设置
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.SETTING",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initSettingViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //中奖纪录
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.WINNING_RECORD",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initWinRecordListViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 活动任务中奖记录
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.TASK_WINNING_RECORD_LIST",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initMissionRecordListViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 服务热线
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.SERVICE_PHONE",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initServiceHotlineViewController:@{@"title": serviceName}];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    // 融汇物业服务
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.TABSERVER",bundleId]]) {
        [[SEGUhomeMediator sharedInstance]seg_selctedToTabWithAction:@"TAB_PROPERTY"];
        return;
    }
    
    //跳转到ABB
    if ([action isEqualToString:@"rudolph.intent.openapi.ACTION"]) {
        NSURL *url = [NSURL URLWithString:@"Rudolphiphone://?uhome2ef5da9a"];
        
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication]openURL:url];
        }else{
            [[[UIAlertView alloc]initWithTitle:nil message:@"找不到跳转的APP" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]show];
        }
        return;
    }
    
    //跳转到梯控
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.CONTROL_ELEVATOR",bundleId]]) {
        //        [SEGAlertView showTmepMessageWithMessage:@"敬请期待！"];
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initElevatorControlViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //一键开门
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.OPEN_DOOR_LIST",bundleId]]) {
        // 小区未开通的时候进行提示
        SEGEnumOpendoorShowType type = [SEGProfileManager openDoorType];
        if (type == SEGEnumOpendoorShowType_NoCooperation) {
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:nil message:@"亲~您所在的小区尚未开通此功能" preferredStyle:UIAlertControllerStyleAlert];
            [alter addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            UIViewController *currentVC = [[SEGUhomeMediator sharedInstance] seg_getCurrentController:nil];
            [currentVC presentViewController:alter animated:YES completion:nil];
            return;
        }
        
        UIViewController *targetVC = [[SEGUhomeMediator sharedInstance] seg_showDoorWithType:0 showedCallBack:^(NSDictionary *info) {
            if ([info[@"type"] isEqualToString:@"AFTERFDOOROPEN"] && [info[@"doorStatus"] integerValue] == 1) {
            }
        }];
        if (targetVC) {
            UIViewController *currentVC = [[SEGUhomeMediator sharedInstance] seg_getCurrentController:nil];
            SEGBasicNavigationController *nav = [[SEGBasicNavigationController alloc]initWithRootViewController:targetVC];
            nav.navigationBarHidden = YES;
            nav.modalPresentationStyle = UIModalPresentationOverFullScreen;
            [currentVC presentViewController:nav animated:NO completion:nil];
        }
        return;
    }
    
    
    //邀请邻居
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.SHARE_APP_NEW",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initSEGInviteQRCodeViewController:nil];
        VC.title = serviceName;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    //新租赁发布-测试
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.LEASE_PUBLISH",bundleId]]) {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initPublishHouseListViewController:nil];
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    //消息中心
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.MSG_CENTER",bundleId]]) {
        [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance] seg_initMessageRootViewController:nil] animated:YES];
        return;
    }
    
    // 跳转消息中心的Tab
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.TABMSG",bundleId]]) {
        [[SEGUhomeMediator sharedInstance]seg_selctedToTabWithAction:@"TAB_MESSAGE"];
        return;
    }
    
    // 渤海钱包
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.CLOUD_ACCOUNTS",bundleId]]) {
        NSMutableDictionary *dicM = [NSMutableDictionary dictionary];
        [dicM setValue:pushVC forKey:@"vc"];
        [[SEGUhomeMediator sharedInstance] seg_pushToWallet:dicM];
        return;
    }
    
    // action跳转小程序
    if ([action isEqualToString:[NSString stringWithFormat:@"%@.action.WX_MINI_PROGRAM",bundleId]]) {
        NSString *wxUserName = [[params allKeys]containsObject:@"wxUserName"] ? ValueToString([params valueForKey:@"wxUserName"]) : @"";
        if (wxUserName.length == 0) {
            [SEGAlertView showTmepMessageWithMessage:@"小程序跳转参数配置错误"];
        }else {
            if (![WXApi isWXAppInstalled]) {
                [SEGAlertView showTmepMessageWithMessage:@"请先安装微信！"];
                return ;
            }
            
            if (![WXApi isWXAppSupportApi]) {
                [SEGAlertView showTmepMessageWithMessage:@"当前微信的版本不支持OpenApi!"];
                return ;
            }
            [self jumpToWXMiniProgramWithParams:params];
        }
 
        return;
    }
    
    [SEGAlertView showTmepMessageWithMessage:@"无法进入该功能"];
}

- (void)jumpToWXMiniProgramWithParams:(NSDictionary *)dict {
    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
    NSString *wxUserName = [[dict allKeys]containsObject:@"wxUserName"] ? ValueToString([dict valueForKey:@"wxUserName"]) : @"";
    NSString *wxMiniProgramType = [[dict allKeys]containsObject:@"wxMiniProgramType"] ? ValueToString([dict valueForKey:@"wxMiniProgramType"]) : @"0";//默认为0
    NSString *wxPath = [[dict allKeys]containsObject:@"wxPath"] ? ValueToString([dict valueForKey:@"wxPath"]) : @"";
    //路径需要替换一下参数
    wxPath = [SEGWebViewLoadManager segReplaceUrlStringWithUrlString:wxPath];
    
    launchMiniProgramReq.userName = wxUserName;  //拉起的小程序的username
    NSString *path = wxPath;
    NSArray *arr = [path componentsSeparatedByString:@"?"];
    //对path后面的参数进行urlencode 但是&和=号不进行urlencode
    CFStringEncoding cfEncoding = CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding);
    NSString *encoded = (__bridge_transfer NSString *)
    CFURLCreateStringByAddingPercentEscapes(
                                            kCFAllocatorDefault,
                                            (__bridge CFStringRef)arr.lastObject,
                                            NULL,
                                            CFSTR("!#$'()*+,/:;?@[]"),
                                            cfEncoding);//原来为!#$&'()*+,/:;=?@[]

    launchMiniProgramReq.path = [NSString stringWithFormat:@"%@?%@",arr.firstObject,encoded];    ////拉起小程序页面的可带参路径，不填默认拉起小程序首页，对于小游戏，可以只传入 query 部分，来实现传参效果，如：传入 "?foo=bar"。
    
    launchMiniProgramReq.miniProgramType = [wxMiniProgramType intValue]; //拉起小程序的类型
//    launchMiniProgramReq.extMsg = [dict yy_modelToJSONString];
    [WXApi sendReq:launchMiniProgramReq completion:nil];
}

- (BOOL)checkUserAuthority:(NSArray*)userTypes
{
    SEGProfileModel* curAccount = [SEGProfileManager sharedManager].profile;
    
    if (!userTypes) { //没有配置服务权限，都默认为有权限。
        return 1;
    }
    
    if (![userTypes containsObject:curAccount.type]) { //判断权限数组是否包含目前用户的权限
        
        if ([curAccount.type isEqualToString:@"5"]) {
           
            SEGNewAlertView *alertView = [[SEGNewAlertView alloc] init];
            [alertView showWithAlertTitle:nil text:@"亲~该功能需物业管理处认证后方可使用" buttonTitlesArray:@[@"取消",@"申请认证"] actionBlock:^(NSInteger btnIndex) {
                if (btnIndex == 1) {
                    UIViewController *pushVC = [self currentViewController];
                    [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance] seg_initSubmitUserAtuhViewController:nil] animated:YES];
                }
            }];
            return 0;
        }
        else {
            [SEGAlertView showTmepMessageWithMessage:@"没有权限访问！"];
            return 0;
        }
    }
    else {
        return 1;
    }
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 1000) {
        if (buttonIndex == 0) {
            return;
        }
    }
    else {
        if (buttonIndex == 1) {
            UIViewController *pushVC = [self currentViewController];
            [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance] seg_initSubmitUserAtuhViewController:nil] animated:YES];
        }
    }
}

/**
 * 获取最上层UIViewcolloer
 * @author Sam
 */
- (UIViewController*)currentViewController{
    UIViewController* vc = [UIApplication sharedApplication].delegate.window.rootViewController;
    while (1) {
        if ([vc isKindOfClass:[UITabBarController class]]) {
            vc = ((UITabBarController*)vc).selectedViewController;
        }
        
        if ([vc isKindOfClass:[UINavigationController class]]) {
            vc = ((UINavigationController*)vc).visibleViewController;
        }
        
        if (vc.presentedViewController) {
            vc = vc.presentedViewController;
        }else{
            break;
        }
    }
    return vc;
}

/**
 *  项目中跳转到任意界面-通过类型去跳转
 * @author Sam
 */
-(void)segAction_pushToViewControllerWithType:(NSDictionary *)params{
    UIViewController *pushVC = [self currentViewController];
    
    NSString* typeId = [params objectForKey:@"typeId"];
    NSString* href = [params objectForKey:@"href"];
    
    if ([typeId isEqualToString:@"0"] || !typeId || [typeId isEqualToString:@"1"]) {
        NSDictionary *var = @{@"linkURL":[params valueForKey:@"href"]};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        VC.title = [params valueForKey:@"title"];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"10008"]) { //活动
        NSDictionary *var = @{@"serviceId":ValueToString(href)};
        UIViewController * VC = [[SEGUhomeMediator sharedInstance]seg_initOtherCreateActivityDetailViewController:var];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"10000"]) { //签到有礼
        NSDictionary *var = @{@"linkURL":kWebActivity(kAccountUserID)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        VC.title = @"好运有礼";
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"10007"]) { //团购---Wendy
        NSDictionary *var = @{@"serviceId":href,@"entrance":@(0)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initGroupsShoppingDetailViewController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    if ([typeId isEqualToString:@"10005"]) { //便利购
        NSDictionary *var = @{@"serviceId":href,@"entrance":@(0)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initGroupsShoppingDetailViewController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    if ([typeId isEqualToString:@"10011"]) { //调查
        [SEGAlertView showTmepMessageWithMessage:@"请使用新调查功能！"];
        return;
    }
    if ([typeId isEqualToString:@"10022"]) { //新调查
        if ([[SEGProfileManager sharedManager].profile.type integerValue] == 5) { //如果是未审核用户会提示需要认证
            [SEGAlertView showTmepMessageWithMessage:@"没有访问权限！"];
            return;
        }
        NSDictionary *var = @{@"linkURL":kNewSurvey(href)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        VC.title = [params valueForKey:@"title"];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        
        return;
    }
    if ([typeId isEqualToString:@"15000"]) { //帮帮活动
        NSDictionary *var = @{@"objId":href,@"objName":@""};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initTopicDetailViewController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    if ([typeId isEqualToString:@"16000"]) { //账单缴费
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initBillListViewController:nil];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    if ([typeId isEqualToString:@"100888"]) {//到家服务首页
        NSDictionary *var = @{@"linkURL":kHomeService};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"100999"] || [typeId isEqualToString:@"100998"]){ //到家服务：100998、到家服务商：100999
        NSDictionary *var = @{@"linkURL":href};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"17000"]) { //PGC
        NSDictionary *var = @{@"pictorialId":href};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initPGCDeteailViewController:var];
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"17001"]) //积分商城2.0商品详情页
    {
        NSDictionary *var = @{@"linkURL":kIntegarlCommodityDetail(href)};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"17002"]) //积分商城2.0首页
    {
        NSDictionary *var = @{@"linkURL":kIntegarlShop};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:var];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"18001"]) //活动列表界面
    {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initActivityManageRootViewController:nil];
        VC.hidesBottomBarWhenPushed = YES;
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"18002"]) //活动详情
    {
        NSDictionary *params = @{@"actId":href,@"nav":pushVC.navigationController};
        [[SEGUhomeMediator sharedInstance]seg_goToActivityManageDetailViewController:params];
        return;
    }
    
    if ([typeId isEqualToString:@"18003"]) //邀请邻居界面
    {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initInviteViewController:nil];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
    
    if ([typeId isEqualToString:@"10003"]) //租赁首页
    {
        UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initMenuHouseViewController:nil];
        VC.navigationController.navigationBar.hidden = NO;
        [pushVC.navigationController pushViewController:VC  animated:YES];
        return;
    }
}

/**
 * 通过接口请求执行登录流程操作
 * @author Sam
 */
-(void)segAction_pushToMainViewControllerThroughInterface:(NSDictionary*)params{
    [self segAction_EnterAppRequestLogic:params];
}

/**
 * 通过接口请求执行登录流程操作
 * @author Sam
 */
-(void)segAction_pushToMainViewControllerThroughInterfaceV2:(NSDictionary*)params{
    [self segEnterAppRequestLogicV2:params];
}

-(void)segAction_EnterAppRequestLogic:(NSDictionary*)params{
    // 无论本地有无网络 无账号时直接展示登录界面
    NSString *tel = [SEGLoginV2Manager segUserTelFromLocal];
    NSString *pwd = [SEGLoginV2Manager segUserPasswordFromLocal];
    if (!(tel.length > 0 && pwd.length > 0)) {
        [[SEGUhomeMediator sharedInstance]seg_pushToLoginViewController:nil];
        return;
    }
    
    //检测网络状态
    [[SEGHTTPManager sharedNetworkManager]segNetworkStatus:^(SEGNetworkStatus status) {
        
        switch (status) {
            case SEGNetworkStatusNotReachable://无网状态
            case SEGNetworkStatusUnknown:
            {
                [self segEnterAppNoNetwork];
                break;
            }
            case SEGNetworkStatusViaWWAN://有网状态
            case SEGNetworkStatusViaWiFi:
            {
                [self segEnterAppHaveNetwork:params];
                break;
            }
            default:
                break;
        }
    }];
}

-(void)segEnterAppRequestLogicV2:(NSDictionary*)params{
    //检测网络状态
    [[SEGHTTPManager sharedNetworkManager]segNetworkStatus:^(SEGNetworkStatus status) {
        
        switch (status) {
            case SEGNetworkStatusNotReachable://无网状态
            case SEGNetworkStatusUnknown:
            {
                [self segEnterAppNoNetwork];
                break;
            }
            case SEGNetworkStatusViaWWAN://有网状态
            case SEGNetworkStatusViaWiFi:
            {
                [self segEnterAppHaveNetworkV2:params];
                break;
            }
            default:
                break;
        }
    }];
}

/**
 * 无网状态进入App逻辑处理
 * @author Sam
 * 没网状态直接进入主页
 */
-(void)segEnterAppNoNetwork{
    [[SEGUhomeMediator sharedInstance]seg_pushToMainViewController:nil];
}

/**
 * 有网状态进入App逻辑处理
 * @author Sam
 */
-(void)segEnterAppHaveNetwork:(NSDictionary*)params{
    NSString *tel = [SEGLoginV2Manager segUserTelFromLocal];
    NSString *pwd = [SEGLoginV2Manager segUserPasswordFromLocal];
    
    if (tel.length > 0 && pwd.length > 0) {
        [self segHaveNetworkRequestLogic:params];
    }else{
        [[SEGUhomeMediator sharedInstance]seg_pushToLoginViewController:nil];
    }
}

/**
 * 有网状态进入App逻辑处理
 * @author Sam
 */
-(void)segEnterAppHaveNetworkV2:(NSDictionary*)params{
    NSString *tel = [SEGLoginV2Manager segUserTelFromLocal];
    NSString *pwd = [SEGLoginV2Manager segUserPasswordFromLocal];
    
    if (tel.length > 0 && pwd.length > 0) {
        [self segHaveNetworkRequestLogicV2:params];
    }else{
        [[SEGUhomeMediator sharedInstance]seg_pushToLoginViewController:nil];
    }
}

/**
 * 进入app网络请求：登录 - 用户信息 - 菜单拉取 - 版本更新
 * @author Sam
 */
-(void)segHaveNetworkRequestLogicV2:(NSDictionary*)params{
    // 添加request header
    [SEGHTTPBusinessManager seg_serRequestHeaderDictionary:@{
                                                             @"systemVersionCode":[UIDevice currentDevice].systemVersion,
                                                             @"phoneModel": [[UIDevice currentDevice]machineModelName],
                                                             @"version":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
                                                             @"communityId":kAccountCommunityID,
                                                             @"source":kSource,
                                                             @"platform":kCompanyPlatformCode,
                                                             @"clientType":kAppPlatformCode,
                                                             @"deviceId": [SEGCKeyChainStore stringWithUUIDStringInKeyChainStore],
                                                             @"versionCode":[[NSUserDefaults standardUserDefaults] valueForKey:UserDefaultsClientVersionCodeTypeKey]
                                                             }];
    
    [self seg_requestServer];
    //获取项目业务开关配置
    [[SEGGetCommunityBizConfigManager sharedManager] getCommunityBizConfigWithCommunityId:[SEGProfileManager sharedManager].profile.jobCommunity];
    [[SEGMenulist2Manager sharedManager] segRequestMenuListForTabBarCompleted:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (isSuccessed) {
            [[SEGUhomeMediator sharedInstance] seg_pushToMainViewController:nil];
        }else{//Tab菜单在本地和服务器都不没有,跳转到登录页面从新登录
            [[SEGUhomeMediator sharedInstance] seg_pushToLoginViewController:nil];
        }
    }];
}

/**
 请求服务号数据
 
 @author Sam
 @version V4.7.0
 */
-(void)seg_requestServer{
    [[SEGServicenbrbaseinfoManager sharedManager] requestServicenbrbaseinfoWithCommunityid:kAccountCommunityID finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (isSuccessed && [result isKindOfClass:[NSDictionary class]]) {
            NSDictionary *data= (NSDictionary*)result;
            if ([[data allKeys]containsObject:@"data"] && [[data valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
                [[NSUserDefaults standardUserDefaults]setObject:[data valueForKey:@"data"] forKey:SEGUPropertyNotificationUserDefaults];
            }
        }
    }];
    
}

/**
 * 进入app网络请求：登录 - 用户信息 - 菜单拉取 - 版本更新
 * @author Sam
 */
-(void)segHaveNetworkRequestLogic:(NSDictionary*)params{
    
    // 添加request header
    [SEGHTTPBusinessManager seg_serRequestHeaderDictionary:@{
                                                             @"systemVersionCode":[UIDevice currentDevice].systemVersion,
                                                             @"phoneModel": [[UIDevice currentDevice]machineModelName],
                                                             @"version":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
                                                             @"communityId":kAccountCommunityID,
                                                             @"source":kSource,
                                                             @"platform":kCompanyPlatformCode,
                                                             @"clientType":kAppPlatformCode,
                                                             @"deviceId": [SEGCKeyChainStore stringWithUUIDStringInKeyChainStore],
                                                             @"versionCode":[[NSUserDefaults standardUserDefaults] valueForKey:UserDefaultsClientVersionCodeTypeKey]
                                                             }];
    
    BOOL needShowLoading = [[params allKeys]containsObject:@"ShowLoading"]? [[params valueForKey:@"ShowLoading"] boolValue] : NO;//是否展示loading，4.5.1版本添加
    BOOL isNewUserRegister = [[params allKeys]containsObject:@"isNewUserRegister"]? [[params valueForKey:@"isNewUserRegister"] boolValue] : NO;//是否新注册
    
    /*
     4.9.4 新增安全改造逻辑，
        1、涉及密码的接口会进行加密
        2、第一次打开app需要同意隐私政策
     
     4.9.6 修改自动登录逻辑
        1、如果是手动登录或新注册用户第一次登录需要请求登录接口
        2、其他情况的自动登录不请求登录接口
     */
    
    // 如果自动登录是用户没有同意《用户隐私政策概要》则不自动登录，跳转至登录页面
    if (![SEGSecurityManager isAgreeSecurity]) {
        [[SEGUhomeMediator sharedInstance] seg_pushToLoginViewController:nil];
        return;
    }
    
    if (needShowLoading) [SVProgressHUD show];
    NSString *tel = [SEGLoginV2Manager segUserTelFromLocal];
    NSString *password = [SEGLoginV2Manager segUserPasswordFromLocal];
    
    if (isNewUserRegister) {
        [[SEGLoginV2Manager sharedManager] requestLoginByTel:tel
                                                    password:password
                                                     imgCode:nil
                                                 randomToken:nil
                                                   loginType:@""
                                                    finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                                                        if (!isSuccessed) {
                                                            if (needShowLoading) [SVProgressHUD dismiss];
                                                            [[SEGUhomeMediator sharedInstance] seg_pushToLoginViewController:@{@"message":errorMessage}];
                                                            return;
                                                        }
                                                        [self handleEnterAppLogic:params];
                                                    }];
    } else {
        [self handleEnterAppLogic:params];
    }
}

- (void)handleEnterAppLogic:(NSDictionary*)params {
    BOOL isNewUserRegister = [[params allKeys]containsObject:@"isNewUserRegister"]? [[params valueForKey:@"isNewUserRegister"] boolValue] : NO;//是否新注册，4.9.3版本添加
    BOOL needShowLoading = [[params allKeys]containsObject:@"ShowLoading"]? [[params valueForKey:@"ShowLoading"] boolValue] : NO;//是否展示loading，4.5.1版本添加
    
    if (needShowLoading) [SVProgressHUD show];
    [[SEGProfileManager sharedManager] requestProfilecompleted:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            if (needShowLoading) [SVProgressHUD dismiss];
            [[SEGUhomeMediator sharedInstance] seg_pushToLoginViewController:@{@"message":errorMessage}];
            return;
        }
        
        [SEGHTTPBusinessManager seg_serRequestHeaderDictionary:@{
                                                                 @"systemVersionCode":[UIDevice currentDevice].systemVersion,
                                                                 @"phoneModel": [[UIDevice currentDevice]machineModelName],
                                                                 @"version":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
                                                                 @"communityId":kAccountCommunityID,
                                                                 @"source":kSource,
                                                                 @"platform":kCompanyPlatformCode,
                                                                 @"clientType":kAppPlatformCode,
                                                                 @"deviceId": [SEGCKeyChainStore stringWithUUIDStringInKeyChainStore],
                                                                 @"versionCode":[[NSUserDefaults standardUserDefaults] valueForKey:UserDefaultsClientVersionCodeTypeKey]
                                                                 }];
        
        // 恢复密码为暗文展示
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"seg_PWDSTATUS"];
        
        // 友盟账号统计
        [MobClick profileSignInWithPUID:kAccountUserID provider:kAppPlatformCode];
        
        //获取极光推送要绑定的tag
        [[SEGUhomeMediator sharedInstance] seg_requestGetPushTag:nil];
        //获取项目业务开关配置
        [[SEGGetCommunityBizConfigManager sharedManager] getCommunityBizConfigWithCommunityId:[SEGProfileManager sharedManager].profile.jobCommunity];
        
        //检查是否需要提交用户反馈
        NSString *content = [[NSUserDefaults standardUserDefaults] valueForKey:kSumbitSearchCommunityAdvice];
        if(content && [content isKindOfClass:[NSString class]] && content.length > 0) {
            [[SEGSuggestsaveManager sharedManager] requestSuggestsaveWithContext:content sugType:@"1001" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            }];
            [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kSumbitSearchCommunityAdvice];
        }
        
        //先保存标志，重新获取token后再请求积分行为
        NSString *key = [NSString stringWithFormat:@"%@_%@",kSubmitTokenIsLoginKey,kAccountUserID];//区分用户
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:key];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        if (isNewUserRegister) {
            //先保存标志，重新获取token后再请求积分行为
            NSString *key = [NSString stringWithFormat:@"%@_%@",kSubmitTokenIsNewUserRegisterKey,kAccountUserID];//区分用户
            [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:key];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        
        [self seg_requestServer];
        [[SEGMenulist2Manager sharedManager] segRequestMenuListForTabBarCompleted:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if (needShowLoading) [SVProgressHUD dismiss];
            if (isSuccessed) {
                [[SEGUhomeMediator sharedInstance] seg_pushToMainViewController:nil];
            }else{//Tab菜单在本地和服务器都不没有,跳转到登录页面从新登录
                [[SEGUhomeMediator sharedInstance] seg_pushToLoginViewController:nil];
            }
            [[SEGUhomeMediator sharedInstance] seg_checkVersion:@{}];
        }];
    }];
}

/**
 * 添加网页跳转原生界面
 * @author Sam
 * @version 4.6.0
 */
-(void)segAction_pushToViewControllerWithScheme:(NSDictionary *)params{
    
    UIViewController *pushVC = [self currentViewController];
    
    SEGOpenFromJsType type = [[params allKeys] containsObject:@"type"] ? [[params valueForKey:@"type"] integerValue] : SEGOpenFromJsType_WebView;
    
    switch (type) {
        case SEGOpenFromJsType_WebView:{
            
            NSMutableDictionary *inputParams = [NSMutableDictionary dictionary];
            if ([[params allKeys]containsObject:@"linkURL"]) [inputParams setObject:[params valueForKey:@"linkURL"] forKey:@"linkURL"];
            
            UIViewController *targetVC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:params];
            targetVC.hidesBottomBarWhenPushed = YES;
            [pushVC.navigationController pushViewController:targetVC animated:YES];
            
            break;
        }
        case SEGOpenFromJsType_ActivityList:{
            
            UIViewController *vc = [[SEGUhomeMediator sharedInstance]seg_initActivityManageRootViewController:nil];
            vc.hidesBottomBarWhenPushed = YES;
            [pushVC.navigationController pushViewController:vc animated:YES];
            break;
        }
        case SEGOpenFromJsType_ActivityDetail:{
            
            NSString* actId = [[params allKeys] containsObject:@"id"] ? [params valueForKey:@"id"] : @"";
            NSDictionary *params = @{@"actId":actId,@"nav":pushVC.navigationController};
            
            [[SEGUhomeMediator sharedInstance] seg_goToActivityManageDetailViewController:params];
            
            break;
        }
        case SEGOpenFromJsType_PGC:{
            
            NSString* objId = [[params allKeys] containsObject:@"id"] ? [params valueForKey:@"id"] : @"";
            NSDictionary *params = @{
                                     @"objId":ValueToString(objId),
                                     @"objType":@(SEGEnumNameObjType_PGC)
                                     };
            
            [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance]seg_initPGCDeteailViewController:params] animated:YES];
            break;
        }
        case SEGOpenFromJsType_UGC:{
            
            NSMutableDictionary *inputParams = [NSMutableDictionary dictionary];
            if ([[params allKeys]containsObject:@"id"]) [inputParams setObject:[params valueForKey:@"id"] forKey:@"objId"];
            if ([[params allKeys]containsObject:@"objType"]) [inputParams setObject:[params valueForKey:@"xobjType"] forKey:@"objType"];
            if ([[params allKeys]containsObject:@"operationType"]) [inputParams setObject:[params valueForKey:@"operationType"] forKey:@"operationType"];
            [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance] seg_initNeihborhoodDetailViewController:inputParams] animated:YES];
            break;
        }
        case SEGOpenFromJsType_TopicDetail:{
            
            NSMutableDictionary *inputParams = [NSMutableDictionary dictionary];
            if ([[params allKeys]containsObject:@"id"]) [inputParams setObject:[params valueForKey:@"id"] forKey:@"objId"];
            if ([[params allKeys]containsObject:@"pictorialTitle"]) [inputParams setObject:[params valueForKey:@"pictorialTitle"] forKey:@"objName"];
            
            [pushVC.navigationController pushViewController:[[SEGUhomeMediator sharedInstance]seg_initTopicDetailViewController:inputParams] animated:YES];
            break;
        }
        case SEGOpenFromJsType_NoticeDetail:{
            NSDictionary *inputParams = @{
                                          @"linkURL":kWebCommunityInfo([params valueForKey:@"id"])
                                          };
            
            UIViewController *targetVC = [[SEGUhomeMediator sharedInstance]seg_initWebViewLoadController:inputParams];
            targetVC.title = @"详情";
            [pushVC.navigationController pushViewController:targetVC animated:YES];
            break;
        }
        default:
            break;
    }
}
@end

